package com.community.web.master.controller;


import com.community.common.properties.JwtProperties;
import com.community.common.result.Result;
import com.community.common.utils.JwtUtil;
import com.community.model.entity.User;
import com.community.web.master.domain.dto.GiveRoleDto;
import com.community.web.master.domain.dto.PageRoleDto;
import com.community.web.master.domain.dto.PageUserDto;
import com.community.web.master.domain.dto.UserLoginDto;
import com.community.web.master.domain.vo.PageResult;
import com.community.web.master.domain.vo.UserLoginVo;
import com.community.web.master.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李晶
 * @since 2024-07-02
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/master/user")
@Slf4j
public class UserController {
    @Autowired
    IUserService iUserService;
    @Autowired
    JwtProperties jwtProperties;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Result<UserLoginVo> login(@RequestBody UserLoginDto userLoginDto, HttpServletRequest request){
        log.info("用户登录");
        UserLoginVo userLoginVo = iUserService.login(userLoginDto,request);
        return Result.success(userLoginVo);
    }

    @PostMapping("/logout")
    @ApiOperation("用户退出")
    public Result<String> logout() {
        return Result.success();
    }

    @GetMapping("/pageQuery")
    @ApiOperation("分页查询用户")
    public Result<PageResult> pageQuery(PageUserDto pageUserDto){
        log.info("分页查询用户"+pageUserDto);
        PageResult pageResult =iUserService.pageQuery(pageUserDto);
        return Result.success(pageResult);
    }

    @PutMapping("/giveRole")
    @ApiOperation("赋予用户角色权限")
    public Result giveRole(@RequestBody GiveRoleDto giveRoleDto){
        log.info("赋予用户角色权限"+giveRoleDto);
        iUserService.giveRole(giveRoleDto);
        return Result.success();
    }
}
